#include<iostream>
#include<cstring>
using namespace std;
const int N = 110;
int n;
int g[N][N];
int dis[N];
bool st[N];
int prim()
{
	memset(dis, 0x3f, sizeof(dis));
	dis[1] = 0;
	int res = 0;
	for (int i = 0; i < n; i++) {
		int t = -1;
		for (int j = 1; j <= n; j++) {
			if (!st[j] && (t == -1 || dis[t] > dis[j])) {
				t = j;
			}
		}
		if (i) {
			res += dis[t];
		}
		st[t] = 1;
		for (int j = 1; j <= n; j++) {
			dis[j] = min(dis[j], g[t][j]);
		}
	}
	return res;
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			cin >> g[i][j];
		}
	}
	cout << prim() << endl;
	return 0;
}